/************************************************************************/
/* 
xvidenc opts class include 1 pass and 2 pass profiles
author pengl
date 2008-11-27
*/
/************************************************************************/


#include "StdAfx.h"
#include <stdio.h>
#include ".\xvidencopts.h"

#define XVIDENC_REALTIME_Q		4
#define XVIDENC_FAST_Q			3
#define XVIDENC_HIGH_Q			2
#define XVIDENC_VHIGH_Q			1

static char *gxvidenc_name = "xvidenc_opts";
static char gxvidenc_opts[1024] = {0};

Cxvidencopts::Cxvidencopts(void)
{
	m_level = XVIDENC_REALTIME_Q; 
}

Cxvidencopts::Cxvidencopts(int level) //1-4 VeryHith-High-Fast-Realtime
{
	m_level = level;
	if (level > XVIDENC_REALTIME_Q || level < XVIDENC_VHIGH_Q) {
		m_level = XVIDENC_FAST_Q; 
	}
}

Cxvidencopts::~Cxvidencopts(void)
{
}


char *Cxvidencopts::get_myname() const
{
	return gxvidenc_name;
}
void Cxvidencopts::set_xvidencopts(Ps_xvidencopts opts)
{
	m_xvidenc_opts = *opts;
}

void Cxvidencopts::set_levelq(const int level)
{
	m_level = level;
	if (level > XVIDENC_REALTIME_Q || level < XVIDENC_VHIGH_Q) {
		m_level = XVIDENC_FAST_Q; 
	}
}

int Cxvidencopts::get_levelq() const
{
	return m_level;
}

char *Cxvidencopts::get_opts()
{
	char opts_level[256] = {0};

	switch(m_level) {
	case XVIDENC_REALTIME_Q:
		sprintf(opts_level, "%s", "turbo:nochroma_me:notrellis:max_bframes=0:vhq=0");
		break;
	case XVIDENC_FAST_Q:
		sprintf(opts_level, "%s", "turbo:vhq=0");
		break;
	case XVIDENC_HIGH_Q:
		sprintf(opts_level, "%s", "vhq=2:bvhq=1:chroma_opt:quant_type=mpeg");
		break;
	case XVIDENC_VHIGH_Q:
		sprintf(opts_level, "%s", "chroma_opt:vhq=4:bvhq=1:quant_type=mpeg");
		break;
	default:
		break;
	};
	
	if (*opts_level == 0) {
		sprintf(gxvidenc_opts, "-ovc xvid -xvidencopts pass=%d:bitrate=%d ", 
			m_xvidenc_opts.pass,
			m_xvidenc_opts.xivdenc_bitrate);
	}
	else {
		sprintf(gxvidenc_opts, "-ovc xvid -xvidencopts pass=%d:bitrate=%d:%s ", 
			m_xvidenc_opts.pass,
			m_xvidenc_opts.xivdenc_bitrate,
			opts_level);
	}

	return gxvidenc_opts;
}

